from flask import Flask, jsonify, render_template
import numpy as np
import scipy.io as sio

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')  # 渲染前端HTML页面

@app.route('/get_prediction')
def get_prediction():
    # 以下都是假设数据，请根据实际传值
    outputs= [[0,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,16],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,15,6,6,16,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,6,6,6,6],
        [3,3,3,3,3,1,1,2,2,5,5,6,0,0,0,0]]

    target_names = ['Alfalfa', 'Corn-notill', 'Corn-mintill', 'Corn', 'Grass-pasture', 'Grass-trees',
                    'Grass-pasture-mowed', 'Hay-windrowed', 'Oats', 'Soybean-notill', 'Soybean-mintill',
                    'Soybean-clean', 'Wheat', 'Woods', 'Buildings-Grass-Trees-Drives', 'Stone-Steel-Towers']

    each_acc = [91.30, 97.69, 98.91, 100.0, 99.79, 97.53, 100.0, 100.0, 100.0, 98.25, 97.80, 97.80,
                98.53, 99.84, 96.89, 94.62]
    # 咱们颜色用自定义，不用spectral
    category_colors = [
                '#89442c', '#0200fa', '#fc6500', '#02fd80', '#a24b9d', '#65b0fa',
                '#77fea7', '#395b6d', '#fffc05', '#feff7a', '#fc02fe', '#6401fb',
                '#00aff4', '#05fc05', '#aab153', '#60c03a'
            ]
    response = {
        'outputs': outputs,
        'target_names': target_names,
        'each_acc': each_acc,
        'category_colors': category_colors
    }

    return jsonify(response)


if __name__ == '__main__':
    app.run(debug=True)
